package corej.course.collection.list;

import java.util.*;

public class TestListSort {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        List list = new ArrayList();
        /*
           * list.add("Liucy"); list.add("Liuxf"); list.add("Huxz");
           * list.add("ZhuGeorge");
           */
        /*
           * list.add(new Integer(10)); list.add(new Integer(20)); list.add(new
           * Integer(8)); list.add(new Integer(15));
           */
        list.add(new Student("Liucy", 30));
        list.add(new Student("Liuxf", 31));
        list.add(new Student("Huxz", 18));
        list.add(new Student("George", 40));

        Collections.sort(list);

        print(list);
    }

    public static void print(Collection c) {
        Iterator it = c.iterator();
        while (it.hasNext()) {
            Object o = it.next();
            System.out.println(o);
        }
    }
}

class Student implements Comparable {
    String name;

    int age;

    public Student(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }

    public String toString() {
        return "Student " + name + "   " + age;
    }

    public int compareTo(Object o) {
        Student s = (Student) o;
        /*
           * if (this.age<s.age) return -1; else if (this.age>s.age) return 1;
           * else return 0;
           */
        // return s.age-this.age;
        return this.name.compareTo(s.name) * (-1);
    }
}
